package com.ruoyi.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.ServiceCode;
import com.ruoyi.service.service.IServiceCodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 验证码表Controller
 * 
 * @author ZDL
 * @date 2024-12-03
 */
@RestController
@RequestMapping("/service/code")
public class ServiceCodeController extends BaseController
{
    @Autowired
    private IServiceCodeService serviceCodeService;

    /**
     * 查询验证码表列表
     */
    @PreAuthorize("@ss.hasPermi('service:code:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceCode serviceCode)
    {
        startPage();
        List<ServiceCode> list = serviceCodeService.selectServiceCodeList(serviceCode);
        return getDataTable(list);
    }

    /**
     * 导出验证码表列表
     */
    @PreAuthorize("@ss.hasPermi('service:code:export')")
    @Log(title = "验证码表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceCode serviceCode)
    {
        List<ServiceCode> list = serviceCodeService.selectServiceCodeList(serviceCode);
        ExcelUtil<ServiceCode> util = new ExcelUtil<ServiceCode>(ServiceCode.class);
        util.exportExcel(response, list, "验证码表数据");
    }

    /**
     * 获取验证码表详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:code:query')")
    @GetMapping(value = "/{codeId}")
    public AjaxResult getInfo(@PathVariable("codeId") Long codeId)
    {
        return success(serviceCodeService.selectServiceCodeByCodeId(codeId));
    }

    /**
     * 新增验证码表
     */
    @PreAuthorize("@ss.hasPermi('service:code:add')")
    @Log(title = "验证码表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceCode serviceCode)
    {
        return toAjax(serviceCodeService.insertServiceCode(serviceCode));
    }

    /**
     * 修改验证码表
     */
    @PreAuthorize("@ss.hasPermi('service:code:edit')")
    @Log(title = "验证码表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceCode serviceCode)
    {
        return toAjax(serviceCodeService.updateServiceCode(serviceCode));
    }

    /**
     * 删除验证码表
     */
    @PreAuthorize("@ss.hasPermi('service:code:remove')")
    @Log(title = "验证码表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codeIds}")
    public AjaxResult remove(@PathVariable Long[] codeIds)
    {
        return toAjax(serviceCodeService.deleteServiceCodeByCodeIds(codeIds));
    }
}
